const cloud = require('wx-server-sdk')

let db = cloud.database()

exports.main = async (event,context)=>{
	let infos = event.userInfo;
	delete infos['_id']
	console.log(infos.username);
	const result = await cloud.openapi.security.msgSecCheck({
	        "openid": event.data.openid,
	        "scene": 2,
	        "version": 2,
	        "content": event.data.content
	      });
	console.log(result);
	if(result.result.label == 100){
		let ff = await db.collection('message').add({
			data:event.data
		});
		return {'msg':'ok'}
	}else{
		return {'msg':'fail'}
	}
}